package com.lh;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;

/**
 * @Author LH
 * @Date 2023/10/24 17:51
 * @PackageName com.lh
 * @Description: [项目名小写 多个单词用_分隔 | 包名全部小写 | 类 首字母大写 | 变量和方法 首字母小写，多个单词组成时除首字母，其他字母首字母需大写 | 常量 全部大写,多个单词用'_'分割]
 */
public class Generator {
    public static void main(String[] args) {
        AutoGenerator autoGenerator = new AutoGenerator();

        DataSourceConfig dataSource = new DataSourceConfig();
        dataSource.setDriverName("com.mysql.cj.jdbc.Driver");
        dataSource.setPassword("123456");
        dataSource.setUrl("jdbc:mysql://localhost:3306/beyond_platform_db?serverTimezone=GMT%2B8");
        dataSource.setUsername("root");
        autoGenerator.setDataSource(dataSource);

        //配置全局
        GlobalConfig globalConfig = new GlobalConfig();
        globalConfig.setOutputDir("E:/ssm_project/gameproject/src/main/java");
        globalConfig.setOpen(false);//不打开文件
        globalConfig.setAuthor("lh");//作者
        globalConfig.setFileOverride(true);//是否覆盖原始生成的文件
        globalConfig.setMapperName("%sMapper"); //设置数据层接口名,%s表示占位符,指代模块名
        globalConfig.setIdType(IdType.AUTO); //设置ID生成策略
        autoGenerator.setGlobalConfig(globalConfig);

        //设置包名相关配置
        PackageConfig packageConfig = new PackageConfig();
        packageConfig.setParent("com.lh");
        packageConfig.setEntity("domain");
        packageConfig.setMapper("mapper");
        autoGenerator.setPackageInfo(packageConfig);

        //策略配置
        StrategyConfig strategyConfig = new StrategyConfig();
        strategyConfig.setRestControllerStyle(true);
        strategyConfig.setEntityLombokModel(true);
        autoGenerator.setStrategy(strategyConfig);
        strategyConfig.setTablePrefix("ad_","app_","data_");
        autoGenerator.execute();
    }
}
